package cn.hchaojie.spring.day01.beans;

import java.text.DateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

@Service
@Scope("prototype")
public class PostService {
	@Autowired
	CategoryService categoryService;
	
//	@Autowired
//	@Qualifier("service1")		// 如果有同类型的bean，只能根据名字来注入
	@Resource(name = "service1")
	AnnoService annoService;
	
	@Autowired
	DateFormat dateFormat;
	
	public void formatDate() {
		System.out.println(dateFormat.format(new Date()));
	}
	
	public DateFormat getFormmater() {
		return dateFormat;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("PostService [categoryService=");
		builder.append(categoryService);
		builder.append(",annoService=");
		builder.append(annoService);
		builder.append("]");
		return builder.toString();
	}
}
